import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:library_base/base/base_list_state.dart';
import 'package:library_base/constant/constant.dart';
import 'package:library_base/entities/lazy_page_entity.dart';
import 'package:library_base/entities/purchase_order_entity.dart';
import 'package:library_base/ext/list_ext.dart';
import 'package:library_base/ext/theme_data_ext.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:library_base/res/gaps.dart';
import 'package:library_base/res/styles.dart';
import 'package:library_base/route/routers.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:library_base/widget/button/gradient_button.dart';
import 'package:library_base/widget/dialog/dialog_util.dart';
import 'package:library_base/widget/image/local_image.dart';
import 'package:library_base/widget/multi_state_widget/multi_state_widget.dart';
import 'package:module_administrator/page/purchase_payment/purchase_payment_controller.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:module_administrator/page/purchase_payment/purchase_payment_ui.dart';

class PurchasePaymentPage extends StatefulWidget {
  const PurchasePaymentPage({Key? key}) : super(key: key);

  @override
  _PurchasePaymentPageState createState() => _PurchasePaymentPageState();
}

class _PurchasePaymentPageState extends BaseListState<LazyPageEntity<PurchaseOrderEntity>,
    PurchaseOrderEntity, PurchasePaymentPage, PurchasePaymentController> {
  @override
  PurchasePaymentController? registerController() => Get.find<PurchasePaymentController>();

  @override
  void onCreate() {
    super.onCreate();
    setTitle(MultiLanguage.poCompleted.tr);
    setNavigationBarColor(ThemeUtil.getTheme().colorScheme.secondary);
  }

  @override
  Widget getNavBarRightWidget() {
    return filterWell(baseGetxController!.payStatus.value,showFiltration:(paymentStatus){
        var arguments = <String,dynamic>{
          "PaymentStatus":baseGetxController!.payStatus.value,
          "filter":(String paymentStatus){
            baseGetxController!.payStatus.value = paymentStatus;
            baseGetxController!.tryReLoad();
          },
          "reset":(){
            baseGetxController!.payStatus.value = "";
            baseGetxController!.tryReLoad();
          },
        };
        DialogUtil.showOrderScreeningDialog(arguments:arguments);
    });
  }

  @override
  Widget? getMainWidget(BuildContext context) {
    return MultiStateWidget(
      emptyWidget: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            LocalImage('admin_empty', package: Constant.packAdmin(), width: 0.6.sw),
            Text(MultiLanguage.noSuchProduct.tr, style: TextStyles.textSecondary28),
            SizedBox(height: 80.w),
            Row(mainAxisAlignment: MainAxisAlignment.center, children: [
              GradientButton(
                ThemeUtil.getTheme(),
                width: 0.4.sw,
                height: 80.w,
                text: MultiLanguage.reload.tr,
                onPressed: baseGetxController!.tryReLoad,
              ),
            ])
          ]),
      controller: baseGetxController!.multiControllerOut,
      child:null,
      buildChild: (){
        return Container(
          color: ThemeUtil.getTheme().secondaryBgColor(),
          child: Column(
            children: [
              Expanded(
                child: getListView(context, baseGetxController),
              ),
            ],
          ),
        );
      },
    );
  }

  @override
  List<Widget> buildListItem(BuildContext context) {
    return baseGetxController!.listData.value.buildItem((index, element) {
      return buildItem(
          element,
          onPaymentApplication: baseGetxController!.onPaymentApplication,
          onCorrectionOrder: baseGetxController!.onCorrectionOrder,
          onItemClick:(purchaseOrderEntity){
        Get.toNamed(Routers.purchasePaymentDetailPage,arguments: { 'purchaseOrderEntity': purchaseOrderEntity});
      });
    }, dividingLine: () {
      return gapH18;
    });
  }
}
